package com.fastloan.safe.mgt.root.service.impl;

import com.fastloan.safe.mgt.root.dao.CmDefFunResMapper;
import com.fastloan.safe.mgt.root.model.CmDefFunRes;
import com.fastloan.safe.mgt.root.model.CmDefResApi;
import com.fastloan.safe.mgt.root.model.vo.DefMenuVo;
import com.fastloan.safe.mgt.root.service.CmDefFunResService;
import com.fastloan.safe.mgt.root.service.CmDefResApiService;
import com.fastloan.safe.mgt.root.service.CmDefResMenuService;
import com.kawins.base.BaseMapper;
import com.kawins.base.baseabs.BaseServiceImpl;
import com.kawins.util.RegexUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.regex.Pattern;

@Service
public class CmDefFunResServiceImpl extends BaseServiceImpl<CmDefFunRes> implements CmDefFunResService {

    @Autowired
    private CmDefFunResMapper defFunResMapper;

    @Autowired
    private CmDefResMenuService defResMenuService;

    @Autowired
    private CmDefResApiService defResApiService;

    @Override
    protected BaseMapper<CmDefFunRes> buildDao() {
        return defFunResMapper;
    }

    @Override
    public List<CmDefResApi> paramForApi(String value) {
        String url = StringUtils.isBlank(value) ? null :
                Pattern.matches(RegexUtil.REGEX_CHINESE, value) ? null : value;
        String name = StringUtils.isBlank(value) ? null :
                Pattern.matches(RegexUtil.REGEX_CHINESE, value) ? value : null;
        return defResApiService.selectAllByValue(name, url);
    }

    @Override
    public List<DefMenuVo> paramForMenu(String value) {
        return defResMenuService.paramForMenu(value);
    }

    @Override
    public void insertList(List<CmDefFunRes> defFunResList) {
        defFunResMapper.insertList(defFunResList);
    }
}
